#pragma once

#include "Protocol.hpp"
#include <memory>

class NetCal
{
public:
    NetCal()
    {
    }
    ~NetCal()
    {
    }
    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        int x = req->X();
        int y = req->Y();
        char oper = req->Oper();
        std::shared_ptr<Response> resp = Factory::BuildResponseDefault();
        resp->_code = 0;
        resp->_result = 0;
        resp->_desc = "success";
        switch (oper)
        {
        case '+':
            resp->_result = x + y;
            break;
        case '-':
            resp->_result = x - y;
            break;
        case '/':
        {
            if (y == 0)
            {
                resp->_code = 1;
                resp->_desc = "div zero";
            }
            else
                resp->_result = x / y;
        }
        break;
        case '%':
        {
            if (y == 0)
            {
                resp->_code = 2;
                resp->_desc = "mod zero";
            }
            else
                resp->_result = x % y;
        }
        break;
        case '*':
            resp->_result = x * y;
            break;
        default:
        {
            resp->_code = 3;
            resp->_desc = "unkown";
        }
        break;
        }

        return resp;
    }

private:
};
